//
//  CKTabBarViewController.swift
//  CKWeiBo
//
//  Created by 陈科 on 2017/1/4.
//  Copyright © 2017年 CK. All rights reserved.
//

import UIKit

class CKTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //自定义tabBar,才能添加中间的按钮
        let ckTabBar = CKTabBar()
        
        //相当于OC中的self.tabBar = ckTabBar
        //tabBar是swift中的私有类,无法获取,只能通过kvc赋值
        self.setValue(ckTabBar, forKey: "tabBar")

        addChildViewControllers()
    }

    //MARK:
    //MARK:添加所有子控件
    private func addChildViewControllers() {
        //添加子控件
        addChildViewController(vc: CKHomeTableViewController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(vc: CKMessageTableViewController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(vc: CKDiscoverTableViewController(), title: "搜索", imageName: "tabbar_discover")
        addChildViewController(vc: CKProfileTableViewController(), title: "我", imageName: "tabbar_profile")
    }
    
    //MARK:
    //MARK:添加单个子控件
    func addChildViewController(vc: UIViewController, title: String, imageName: String) {
        //添加首页
        let nav = CKBaseNavigationController(rootViewController: vc)
//        let nav = vc
        
        vc.title = title
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orange], for: .selected)
        vc.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        addChildViewController(nav)
    }
    
    
    
    
    

}
